//
//  MemberTestViewController.m
//  cherryproduct
//
//  Created by zou shigang on 14/8/31.
//  Copyright (c) 2014年 cherry. All rights reserved.
//

#import "MemberTestViewController.h"
#import "UIfaceimageview.h"
#import "BuyProductViewController.h"
#import "FIFaceView.h"

@interface MemberTestViewController ()<UITableViewDataSource, UITableViewDelegate, UMSocialUIDelegate, UIAlertViewDelegate>
{
    NSMutableDictionary * data_list;
    NSMutableArray * data_array_list;
    
    UIButton * btn_can;
    
    UIButton * image_goods;
}

@property(nonatomic, strong) UITableView * tableview;

@property(nonatomic, strong) UIImageView * imgProfile;
@property(nonatomic, strong) UIImageView * img_header;

@property(nonatomic, strong) UILabel * label_people;

@property(nonatomic, assign) NSInteger m_useful_sum;
@property(nonatomic, strong) NSString * m_str_content;

@property(nonatomic, assign) double m_start_time;

//new
@property(nonatomic, strong) UIScrollView * m_scrollview_img;
@property(nonatomic, strong) UILabel * m_label_null;
@property(nonatomic, strong) UILabel * m_bb_text_vv;
@property(nonatomic, strong) UIButton * m_btn_more;
@property(nonatomic, strong) UILabel * m_btn_more_label;

@property(nonatomic, assign) BOOL m_b_show_more;

@property(nonatomic, assign) BOOL m_b_show_more_sex;

@end

@implementation MemberTestViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    {
        NSString * new_logo = [[LoginViewController shareUserInfo] objectForKey:@"new_logo"];
        NSString * new_cover = [[LoginViewController shareUserInfo] objectForKey:@"new_cover"];
        if (new_logo) {
            [self.img_header setImageWithURL:[NSURL URLWithString:new_logo]
                            placeholderImage:[UIImage imageNamed:@"bodyheader"]];
        }
        if (new_cover) {
            [self.imgProfile setImageWithURL:[NSURL URLWithString:new_cover]
                            placeholderImage:[UIImage imageNamed:@"user_bg"]];
        }
    }
}

- (void)reloadScrollImg:(NSDictionary*)img_dic
{
    if (img_dic) {
        NSArray * img_arr = [img_dic objectForKey:@"att"];
        if (img_arr && [img_arr isKindOfClass:[NSArray class]] && [img_arr count] > 0) {
            self.m_scrollview_img.hidden=NO;
            self.m_label_null.hidden=YES;
            
            for (int i = 0; i < [img_arr count]; i++) {
                NSDictionary * dic_bb = [img_arr objectAtIndex:i];
                if (dic_bb && [dic_bb isKindOfClass:[NSDictionary class]]) {
                    
                    NSString * str_url = [dic_bb objectForKey:@"url"];
                    if (str_url) {
                        NSString * str_url_new = [NSString stringWithFormat:@"%@%@", JPG, str_url];
                        CGRect r = CGRectMake(i*80+10+i*10, 0, 80, 80);
                        UIButton * btn_bb = [[UIButton alloc] initWithFrame:r];
                        btn_bb.tag=i;
                        [btn_bb addTarget:self action:@selector(doActionShowLargImg:) forControlEvents:UIControlEventTouchUpInside];
                        //[btn_bb setImageForState:UIControlStateNormal withURL:[NSURL URLWithString:str_url_new]];
                        UIImageView * bbb_vv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
                        [bbb_vv setImageWithURL:[NSURL URLWithString:str_url_new]];
                        bbb_vv.contentMode=UIViewContentModeScaleAspectFill;
                        bbb_vv.clipsToBounds=YES;
                        [btn_bb addSubview:bbb_vv];
                        
                        [self.m_scrollview_img addSubview:btn_bb];
                    }
                }
            }
            self.m_scrollview_img.contentSize=CGSizeMake(90*[img_arr count], 80);
        }
    }
}

- (UIView*)getFooterView
{
    CGFloat width = self.view.frame.size.width;
    
    UIView * cell = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 120)];
    cell.backgroundColor=[UIColor whiteColor];
    
    //图片
    {
        self.m_scrollview_img = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, 80)];
        self.m_scrollview_img.backgroundColor=[UIColor whiteColor];
        [cell addSubview:self.m_scrollview_img];
        self.m_scrollview_img.hidden=YES;
        
        if (data_array_list && [data_array_list count] > 0) {
            
            NSDictionary * img_dic = [data_array_list objectAtIndex:0];
            if (img_dic && [img_dic isKindOfClass:[NSDictionary class]]) {
                
                self.m_useful_sum = [[img_dic objectForKey:@"useful_sum"] integerValue];
                self.m_str_content = [img_dic objectForKey:@"content"];
                
                NSArray * img_arr = [img_dic objectForKey:@"att"];
                if (img_arr && [img_arr isKindOfClass:[NSArray class]] && [img_arr count] > 0) {
                    for (int i = 0; i < [img_arr count]; i++) {
                        NSDictionary * dic_bb = [img_arr objectAtIndex:i];
                        if (dic_bb && [dic_bb isKindOfClass:[NSDictionary class]]) {
                            
                            NSString * str_url = [dic_bb objectForKey:@"url"];
                            if (str_url) {
                                NSString * str_url_new = [NSString stringWithFormat:@"%@%@", JPG, str_url];
                                CGRect r = CGRectMake(i*80+10+i*10, 0, 80, 80);
                                UIButton * btn_bb = [[UIButton alloc] initWithFrame:r];
                                btn_bb.tag=i;
                                [btn_bb addTarget:self action:@selector(doActionShowLargImg:) forControlEvents:UIControlEventTouchUpInside];
                                //[btn_bb setImageForState:UIControlStateNormal withURL:[NSURL URLWithString:str_url_new]];
                                UIImageView * bbb_vv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
                                [bbb_vv setImageWithURL:[NSURL URLWithString:str_url_new]];
                                bbb_vv.contentMode=UIViewContentModeScaleAspectFill;
                                bbb_vv.clipsToBounds=YES;
                                [btn_bb addSubview:bbb_vv];
                                
                                [self.m_scrollview_img addSubview:btn_bb];
                            }
                        }
                    }
                    self.m_scrollview_img.contentSize=CGSizeMake(90*[img_arr count], 80);
                } else {
                    self.m_scrollview_img.hidden=YES;
                    UILabel * label_null = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 80)];
                    label_null.backgroundColor=[UIColor clearColor];
                    label_null.font=[UIFont systemFontOfSize:16];
                    label_null.textAlignment=NSTextAlignmentCenter;
                    label_null.textColor=[UIColor grayColor];
                    label_null.text=@"没有评测图片";
                    [cell addSubview:label_null];
                }
            }
        } else {
            self.m_label_null = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 80)];
            self.m_label_null.backgroundColor=[UIColor clearColor];
            self.m_label_null.font=[UIFont systemFontOfSize:16];
            self.m_label_null.textAlignment=NSTextAlignmentCenter;
            self.m_label_null.textColor=[UIColor grayColor];
            self.m_label_null.text=@"没有评测图片";
            [cell addSubview:self.m_label_null];
        }
    }
    
    //最后一行
    {
        UILabel * label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 80, 100, 25)];
        label_temp.numberOfLines=0;
        label_temp.backgroundColor=[UIColor clearColor];
        label_temp.textColor=[UIColor grayColor];
        label_temp.font=[UIFont systemFontOfSize:12];
        [cell addSubview:label_temp];
        
        self.label_people = [[UILabel alloc] initWithFrame:CGRectMake(115, 80, 70, 25)];
        self.label_people.numberOfLines=0;
        self.label_people.backgroundColor=[UIColor clearColor];
        self.label_people.textColor=[UIColor grayColor];
        self.label_people.font=[UIFont systemFontOfSize:12];
        self.label_people.textAlignment=NSTextAlignmentLeft;
        [cell addSubview:self.label_people];
        
        //NSString * addtime = [data_list objectForKey:@"addtime"];
        //NSString * useful_sum = [data_array_list objectForKey:@"comment_sum"];
        if (self.m_start_time != 0) {
            long long time = self.m_start_time;
            NSDate * d = [[NSDate alloc] initWithTimeIntervalSince1970:time];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            dateFormatter.dateFormat = @"yyyy-MM-dd";
            NSString * str_date = [dateFormatter stringFromDate:d];
            label_temp.text=str_date;
        } else {
            NSDate * d = [NSDate date];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            dateFormatter.dateFormat = @"yyyy-MM-dd";
            NSString * str_date = [dateFormatter stringFromDate:d];
            label_temp.text=str_date;
        }
        
        NSString * str_bb = [NSString stringWithFormat:@"%d人觉得赞", self.m_useful_sum];
        self.label_people.text=str_bb;
    }
    //添加按钮
    {
        UIButton * btn_share = [[UIButton alloc] initWithFrame:CGRectMake(200, 83, 45, 22)];
        //[btn_share setImage:[UIImage imageNamed:@"btn_my_share"] forState:UIControlStateNormal];
        btn_share.backgroundColor=[UIColor clearColor];
        
        UIImageView * img_temp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, 12, 12)];
        img_temp.image=[UIImage imageNamed:@"so_share"];
        [btn_share addSubview:img_temp];
        
        UILabel * label_temp = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 45-12, 22)];
        label_temp.backgroundColor=[UIColor clearColor];
        label_temp.textAlignment=NSTextAlignmentCenter;
        label_temp.textColor=RGBCOLOR(81, 181, 243);
        label_temp.font=[UIFont systemFontOfSize:13];
        label_temp.text=@"分享";
        [btn_share addSubview:label_temp];
        [cell addSubview:btn_share];
        
        
        btn_can = [[UIButton alloc] initWithFrame:CGRectMake(260, 83, 45, 22)];
        //[btn_can setImage:[UIImage imageNamed:@"btn_my_can"] forState:UIControlStateNormal];
        
        img_temp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, 12, 12)];
        img_temp.image=[UIImage imageNamed:@"so_delete"];
        [btn_can addSubview:img_temp];
        
        label_temp = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 45-12, 22)];
        label_temp.backgroundColor=[UIColor clearColor];
        label_temp.textAlignment=NSTextAlignmentCenter;
        label_temp.textColor=RGBCOLOR(81, 181, 243);
        label_temp.font=[UIFont systemFontOfSize:13];
        label_temp.text=@"删除";
        [btn_can addSubview:label_temp];
        
        [cell addSubview:btn_can];
        
        
        [btn_share addTarget:self action:@selector(haveShare:) forControlEvents:UIControlEventTouchUpInside];
        [btn_can addTarget:self action:@selector(doActionDelete:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return cell;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.myView.hidden = YES;
    [self setNavigationBarColor:[UIColor clearColor]];
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGFloat width = self.view.frame.size.width;
    
    if (self.imgProfile==nil) {
        self.imgProfile = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, 164)];
        self.imgProfile.contentMode=UIViewContentModeScaleAspectFill;
        self.imgProfile.clipsToBounds=YES;
        [self.imgProfile setImage:[UIImage imageNamed:@"user_bg"]];
        [self.view addSubview:self.imgProfile];
    }
    
    if (self.tableview == nil) {
        self.tableview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        self.tableview.backgroundColor=[UIColor clearColor];
        self.tableview.dataSource=self;
        self.tableview.delegate=self;
        self.tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
        self.tableview.showsVerticalScrollIndicator=NO;
        
        UIView * view_header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 164)];
        view_header.backgroundColor=[UIColor clearColor];
        {
            UIButton * btn_header = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-35, 60, 70, 70)];
            btn_header.backgroundColor=[UIColor clearColor];
            
            self.img_header = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
            self.img_header.userInteractionEnabled = YES;
            self.img_header.image = [UIImage imageNamed:@"bodyheader"];
            self.img_header.userInteractionEnabled=NO;
            
            self.img_header.layer.cornerRadius = 35;
            self.img_header.layer.masksToBounds = YES;
            self.img_header.layer.borderWidth = 3.0;
            self.img_header.layer.borderColor = [UIColor whiteColor].CGColor;
            
            [btn_header addSubview:self.img_header];
            
            [view_header addSubview:btn_header];
        }
        self.tableview.tableHeaderView=view_header;
        self.tableview.tableFooterView=[self getFooterView];
        
        [self.view addSubview:self.tableview];
    }
    
    {
        UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, IOS7_OR_LATER?20:0, [UIImage imageNamed:@"topBack.png"].size.width-5, 44)];
        if (IOS7_OR_LATER) {
            [backButton setImage:[UIImage imageNamed:@"topBack.png"] forState:UIControlStateNormal];
            [backButton setImage:[UIImage imageNamed:@"topBack.png"] forState:UIControlStateHighlighted];
        } else {
            [backButton setBackgroundImage:[UIImage imageNamed:@"topBack.png"] forState:UIControlStateNormal];
            [backButton setBackgroundImage:[UIImage imageNamed:@"topBack.png"] forState:UIControlStateHighlighted];
        }
        [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:backButton];
        
        UILabel * label_title = [[UILabel alloc] initWithFrame:CGRectMake(50, 20, width-100, 44)];
        label_title.textColor = [UIColor whiteColor];
        label_title.backgroundColor = [UIColor clearColor];
        label_title.font = [UIFont systemFontOfSize:20];
        label_title.textAlignment = NSTextAlignmentCenter;
        label_title.text = @"我的评测";
        [self.view addSubview:label_title];
    }
    
    [self getData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark MarkHeader

static CGFloat ImageHeight  = 164.f;
static CGFloat ImageWidth  = 320.0;

- (void)updateImg {
    CGFloat yOffset   = self.tableview.contentOffset.y;
    CGFloat f_height = 0;
    
    if (yOffset < 0) {
        CGFloat factor = ((ABS(yOffset)+ImageHeight)*ImageWidth)/ImageHeight;
        CGRect f = CGRectMake(-(factor-ImageWidth)/2, f_height, factor, ImageHeight+ABS(yOffset));
        self.imgProfile.frame = f;
    } else {
        CGRect f = self.imgProfile.frame;
        f.origin.y = f_height-yOffset;
        self.imgProfile.frame = f;
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self updateImg];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark -
#pragma mark GetData
- (void)getData
{
    [self.view startLoadingAnimation];
    
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:self.str_id,@"id", nil];
    
    [[HttpNewBaseService sharedClient] getRequestOperation:@"goods_comment/comment_show" paramDictionary:dic onCompletion:^(NSString *responseString) {
        [self.view stopLoadingAnimation];
        @try {
            NSDictionary * dic =[responseString JSONValue];
            if ([[dic objectForKey:@"status"] intValue] == 1) {
                NSDictionary * data = [dic objectForKey:@"data"];
                if (data) {
                    NSDictionary * goods = [data objectForKey:@"goods"];
                    if (goods) {
                        data_list = [[NSMutableDictionary alloc] initWithDictionary:goods copyItems:YES];
                    }
                    NSArray * comment = [data objectForKey:@"comment"];
                    if (comment && [comment isKindOfClass:[NSArray class]]) {
                        data_array_list = [[NSMutableArray alloc] initWithArray:comment copyItems:YES];
                        if ([data_array_list count] > 0) {
                            self.m_start_time = [[[data_array_list objectAtIndex:0] objectForKey:@"addtime"] doubleValue];
                        }
                    }
                    
                    [self.tableview reloadData];
                }
            } else {
                [self showAlertView:@"温馨提示" subtitle:[dic objectForKey:@"message"]];
            }
        } @catch (NSException *exception) {
            [self showAlertView:@"温馨提示" subtitle:@"服务器异常！"];
        } @finally {
        }
    } onError:^(NSError *error) {
        [self.view stopLoadingAnimation];
        [self showAlertView:@"温馨提示" subtitle:@"网络断了！"];
    } onAnimated:YES];
}

#pragma mark -
#pragma mark UITableViewDataSource UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    if (self.m_b_show_more_sex) {
        return 450;
    }
    return 450-120;
}

- (CGSize)getFontSize:(NSString*)str
{
    CGFloat width = self.view.frame.size.width;
    
    CGSize labelSize = [str sizeWithFont:[UIFont systemFontOfSize:12]
                       constrainedToSize:CGSizeMake(width-30, 10000.0f)
                           lineBreakMode:NSLineBreakByCharWrapping];
    
    return labelSize;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString * str_cell = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str_cell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str_cell];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    if (self.m_b_show_more) {
        
        CGFloat width = self.view.frame.size.width;
        if (self.m_b_show_more_sex) {
            CGSize size_font = [self getFontSize:self.m_str_content];
            self.m_bb_text_vv.frame = CGRectMake(15, 245, width-30, size_font.height+5);
            
            self.m_btn_more.frame = CGRectMake(width-80, 245+size_font.height+10, 70, 25);
            
            self.m_btn_more_label.text=@"收起评论";
        } else {
            self.m_bb_text_vv.frame = CGRectMake(15, 245, width-30, 55);
            self.m_btn_more.frame = CGRectMake(width-80, 300, 70, 25);
            
            self.m_btn_more_label.text=@"全部显示";
        }
        
        return cell;
    }
    
    if (data_list) {
        CGFloat width = self.view.frame.size.width;
        //标题
        UILabel * label_title = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, width-30-80, 30)];
        label_title.backgroundColor=[UIColor clearColor];
        label_title.textColor=[UIColor grayColor];
        label_title.font=[UIFont systemFontOfSize:14];
        [cell addSubview:label_title];
        
        NSString * str_name = [data_list objectForKey:@"name"];
        if (str_name) {
            NSString * str_bb = [NSString stringWithFormat:@"您点评了 \"%@\"", str_name];
            label_title.text = str_bb;
        }
        //图片
        image_goods = [[UIButton alloc] initWithFrame:CGRectMake(120, 50, 80, 80)];
        [cell addSubview:image_goods];
        
        NSString * str_img_url = [data_list objectForKey:@"photo"];
        if (str_img_url) {
            NSString * str_bb = [NSString stringWithFormat:@"%@%@", JPG, str_img_url];
            //[image_goods setImageWithURL:[NSURL URLWithString:str_bb] placeholderImage:nil];
            [image_goods setImageForState:UIControlStateNormal withURL:[NSURL URLWithString:str_bb]];
            [image_goods addTarget:self action:@selector(doActionBBQ:) forControlEvents:UIControlEventTouchUpInside];
        }
        //星星
        {
            UILabel * label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 135, 120, 25)];
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.font=[UIFont systemFontOfSize:12];
            label_temp.textColor=[UIColor grayColor];
            label_temp.text = @"好用指数";
            [cell addSubview:label_temp];
            
            label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 160, 120, 25)];
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.font=[UIFont systemFontOfSize:12];
            label_temp.textColor=[UIColor grayColor];
            label_temp.text = @"性价比指数";
            [cell addSubview:label_temp];
            
            label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 185, 120, 25)];
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.font=[UIFont systemFontOfSize:12];
            label_temp.textColor=[UIColor grayColor];
            label_temp.text = @"使用频繁度指数";
            [cell addSubview:label_temp];
            
            label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 210, 120, 25)];
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.font=[UIFont systemFontOfSize:12];
            label_temp.textColor=[UIColor grayColor];
            label_temp.text = @"安全性指数";
            [cell addSubview:label_temp];
            
            /*
             forKey:@"gooduse_exp"];
             forKey:@"try_exp"];
             forKey:@"costs_exp"];
             forKey:@"safety_exp"];
             */
            
            NSInteger a = 0;//[[data_list objectForKey:@"gooduse_exp"] integerValue];
            NSInteger c = 0;//[[data_list objectForKey:@"try_exp"] integerValue];
            NSInteger b = 0;//[[data_list objectForKey:@"costs_exp"] integerValue];
            NSInteger d = 0;//[[data_list objectForKey:@"safety_exp"] integerValue];
            
            if (data_array_list && [data_array_list isKindOfClass:[NSArray class]]) {
                if ([data_array_list count] > 0) {
                    NSDictionary * dic_bb = [data_array_list objectAtIndex:0];
                    if (dic_bb && [dic_bb isKindOfClass:[NSDictionary class]]) {
                        a = [[dic_bb objectForKey:@"gooduse_exp"] integerValue];
                        b = [[dic_bb objectForKey:@"costs_exp"] integerValue];
                        c = [[dic_bb objectForKey:@"try_exp"] integerValue];
                        d = [[dic_bb objectForKey:@"safety_exp"] integerValue];
                    }
                }
            }
            
            UIImage * image_select_yes = [UIImage imageNamed:@"productreviewsup"];
            UIImage * image_select_no  = [UIImage imageNamed:@"productreviewsdown"];
            for (int i = 0; i < 5; i++) {
                UIImageView * img_star = [[UIImageView alloc] initWithFrame:CGRectMake(75+i*18, 140, 15, 15)];
                img_star.image=image_select_yes;
                if (i >= a) {
                    img_star.image=image_select_no;
                }
                [cell addSubview:img_star];
            }
            for (int i = 0; i < 5; i++) {
                UIImageView * img_star = [[UIImageView alloc] initWithFrame:CGRectMake(85+i*18, 165, 15, 15)];
                img_star.image=image_select_yes;
                if (i >= b) {
                    img_star.image=image_select_no;
                }
                [cell addSubview:img_star];
            }
            for (int i = 0; i < 5; i++) {
                UIImageView * img_star = [[UIImageView alloc] initWithFrame:CGRectMake(105+i*18, 190, 15, 15)];
                img_star.image=image_select_yes;
                if (i >= c) {
                    img_star.image=image_select_no;
                }
                [cell addSubview:img_star];
            }
            for (int i = 0; i < 5; i++) {
                UIImageView * img_star = [[UIImageView alloc] initWithFrame:CGRectMake(85+i*18, 215, 15, 15)];
                img_star.image=image_select_yes;
                if (i >= d) {
                    img_star.image=image_select_no;
                }
                [cell addSubview:img_star];
            }
        }
        //图片
        {
            if (data_array_list && [data_array_list count] > 0) {
//                UIScrollView * scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 305, width, 80)];
//                scrollview.backgroundColor=[UIColor whiteColor];
//                [cell addSubview:scrollview];
                
                NSDictionary * img_dic = [data_array_list objectAtIndex:0];
                if (img_dic && [img_dic isKindOfClass:[NSDictionary class]]) {
                    
                    self.m_useful_sum = [[img_dic objectForKey:@"useful_sum"] integerValue];
                    self.m_str_content = [img_dic objectForKey:@"content"];
                    
                    [self reloadScrollImg:img_dic];
//                    NSArray * img_arr = [img_dic objectForKey:@"att"];
//                    if (img_arr && [img_arr isKindOfClass:[NSArray class]] && [img_arr count] > 0) {
//                        for (int i = 0; i < [img_arr count]; i++) {
//                            NSDictionary * dic_bb = [img_arr objectAtIndex:i];
//                            if (dic_bb && [dic_bb isKindOfClass:[NSDictionary class]]) {
//                                
//                                NSString * str_url = [dic_bb objectForKey:@"url"];
//                                if (str_url) {
//                                    NSString * str_url_new = [NSString stringWithFormat:@"%@%@", JPG, str_url];
//                                    CGRect r = CGRectMake(i*80+10+i*10, 0, 80, 80);
//                                    UIButton * btn_bb = [[UIButton alloc] initWithFrame:r];
//                                    btn_bb.tag=i;
//                                    [btn_bb addTarget:self action:@selector(doActionShowLargImg:) forControlEvents:UIControlEventTouchUpInside];
//                                    //[btn_bb setImageForState:UIControlStateNormal withURL:[NSURL URLWithString:str_url_new]];
//                                    UIImageView * bbb_vv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
//                                    [bbb_vv setImageWithURL:[NSURL URLWithString:str_url_new]];
//                                    bbb_vv.contentMode=UIViewContentModeScaleAspectFill;
//                                    bbb_vv.clipsToBounds=YES;
//                                    [btn_bb addSubview:bbb_vv];
//                                    
//                                    [scrollview addSubview:btn_bb];
//                                }
//                            }
//                        }
//                        scrollview.contentSize=CGSizeMake(90*[img_arr count], 80);
//                    } else {
//                        scrollview.hidden=YES;
//                        UILabel * label_null = [[UILabel alloc] initWithFrame:CGRectMake(0, 305, width, 80)];
//                        label_null.backgroundColor=[UIColor clearColor];
//                        label_null.font=[UIFont systemFontOfSize:16];
//                        label_null.textAlignment=NSTextAlignmentCenter;
//                        label_null.textColor=[UIColor grayColor];
//                        label_null.text=@"没有评测图片";
//                        [cell addSubview:label_null];
//                    }
                }
            } else {
//                UILabel * label_null = [[UILabel alloc] initWithFrame:CGRectMake(0, 305, width, 80)];
//                label_null.backgroundColor=[UIColor clearColor];
//                label_null.font=[UIFont systemFontOfSize:16];
//                label_null.textAlignment=NSTextAlignmentCenter;
//                label_null.textColor=[UIColor grayColor];
//                label_null.text=@"没有评测图片";
//                [cell addSubview:label_null];
            }
        }
        
        {
            if (self.m_str_content && ![self.m_str_content isKindOfClass:[NSNull class]]) {

//                UITextView * text_vv = [[UITextView alloc] initWithFrame:CGRectMake(15, 245, width-30, 55)];
//                text_vv.text=self.m_str_content;
//                //text_vv.userInteractionEnabled=NO;
//                [text_vv setEditable:NO];
//                [cell addSubview:text_vv];
                
                self.m_bb_text_vv = [[UILabel alloc] initWithFrame:CGRectMake(15, 245, width-30, 55)];
                self.m_bb_text_vv.text=self.m_str_content;
                self.m_bb_text_vv.font=[UIFont systemFontOfSize:12];
                self.m_bb_text_vv.numberOfLines=0;
                //text_vv.userInteractionEnabled=NO;
                //[text_vv setEditable:NO];
                [cell addSubview:self.m_bb_text_vv];
                
                CGSize size_font = [self getFontSize:self.m_str_content];
                if (size_font.height > 55) {
                    self.m_btn_more = [[UIButton alloc] initWithFrame:CGRectMake(width-90, 300, 70, 25)];
                    self.m_btn_more.backgroundColor=[UIColor clearColor];
                    
                    self.m_btn_more_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 25)];
                    self.m_btn_more_label.textAlignment=NSTextAlignmentCenter;
                    self.m_btn_more_label.text=@"全部显示";
                    self.m_btn_more_label.font=[UIFont systemFontOfSize:12];
                    self.m_btn_more_label.textColor=RGBCOLOR(122, 174, 255);
                    self.m_btn_more_label.backgroundColor=[UIColor clearColor];
                    [self.m_btn_more addSubview:self.m_btn_more_label];
                    
                    [self.m_btn_more addTarget:self action:@selector(doMoreShow:) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:self.m_btn_more];
                }
            } else {
                UILabel * label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 245, width-30, 55)];
                label_temp.numberOfLines=0;
                label_temp.backgroundColor=[UIColor clearColor];
                label_temp.textColor=[UIColor grayColor];
                label_temp.font=[UIFont systemFontOfSize:14];
                [cell addSubview:label_temp];
                label_temp.text = @"没有写评论,服务器返回null!";
                [cell addSubview:label_temp];
            }
        }
        
        /*
        //最后一行
        {
            UILabel * label_temp = [[UILabel alloc] initWithFrame:CGRectMake(15, 385, 100, 25)];
            label_temp.numberOfLines=0;
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.textColor=[UIColor grayColor];
            label_temp.font=[UIFont systemFontOfSize:12];
            [cell addSubview:label_temp];
            
            self.label_people = [[UILabel alloc] initWithFrame:CGRectMake(115, 385, 70, 25)];
            self.label_people.numberOfLines=0;
            self.label_people.backgroundColor=[UIColor clearColor];
            self.label_people.textColor=[UIColor grayColor];
            self.label_people.font=[UIFont systemFontOfSize:12];
            self.label_people.textAlignment=NSTextAlignmentLeft;
            [cell addSubview:self.label_people];
            
            //NSString * addtime = [data_list objectForKey:@"addtime"];
            //NSString * useful_sum = [data_array_list objectForKey:@"comment_sum"];
            if (self.m_start_time != 0) {
                long long time = self.m_start_time;
                NSDate * d = [[NSDate alloc] initWithTimeIntervalSince1970:time];
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                dateFormatter.dateFormat = @"yyyy-MM-dd";
                NSString * str_date = [dateFormatter stringFromDate:d];
                label_temp.text=str_date;
            } else {
                NSDate * d = [NSDate date];
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                dateFormatter.dateFormat = @"yyyy-MM-dd";
                NSString * str_date = [dateFormatter stringFromDate:d];
                label_temp.text=str_date;
            }
            
            NSString * str_bb = [NSString stringWithFormat:@"%d人觉得赞", self.m_useful_sum];
            self.label_people.text=str_bb;
        }
        //添加按钮
        {
            UIButton * btn_share = [[UIButton alloc] initWithFrame:CGRectMake(200, 388, 45, 22)];
            //[btn_share setImage:[UIImage imageNamed:@"btn_my_share"] forState:UIControlStateNormal];
            btn_share.backgroundColor=[UIColor clearColor];
            
            UIImageView * img_temp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, 12, 12)];
            img_temp.image=[UIImage imageNamed:@"so_share"];
            [btn_share addSubview:img_temp];
            
            UILabel * label_temp = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 45-12, 22)];
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.textAlignment=NSTextAlignmentCenter;
            label_temp.textColor=RGBCOLOR(81, 181, 243);
            label_temp.font=[UIFont systemFontOfSize:13];
            label_temp.text=@"分享";
            [btn_share addSubview:label_temp];
            [cell addSubview:btn_share];
            
            
            btn_can = [[UIButton alloc] initWithFrame:CGRectMake(260, 388, 45, 22)];
            //[btn_can setImage:[UIImage imageNamed:@"btn_my_can"] forState:UIControlStateNormal];
            
            img_temp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, 12, 12)];
            img_temp.image=[UIImage imageNamed:@"so_delete"];
            [btn_can addSubview:img_temp];
            
            label_temp = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 45-12, 22)];
            label_temp.backgroundColor=[UIColor clearColor];
            label_temp.textAlignment=NSTextAlignmentCenter;
            label_temp.textColor=RGBCOLOR(81, 181, 243);
            label_temp.font=[UIFont systemFontOfSize:13];
            label_temp.text=@"删除";
            [btn_can addSubview:label_temp];
            
            [cell addSubview:btn_can];
            
            
            [btn_share addTarget:self action:@selector(haveShare:) forControlEvents:UIControlEventTouchUpInside];
            [btn_can addTarget:self action:@selector(doActionDelete:) forControlEvents:UIControlEventTouchUpInside];
        }*/
    }
    
    return cell;
}

- (void)doMoreShow:(id)sender
{
    self.m_b_show_more = YES;
    
    self.m_b_show_more_sex = !self.m_b_show_more_sex;
    
    [self.tableview reloadData];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)doActionDelete:(UIButton*)sender
{
    sender.enabled=NO;
    
    NSString * str_bb_id = @"0";
    if (data_array_list && [data_array_list isKindOfClass:[NSArray class]]) {
        if ([data_array_list count] > 0) {
            NSDictionary * dic_bb = [data_array_list objectAtIndex:0];
            if (dic_bb && [dic_bb isKindOfClass:[NSDictionary class]]) {
                str_bb_id = [dic_bb objectForKey:@"id"];
            }
        }
    }
    
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:str_bb_id, @"id", nil];
    
    [self.view startLoadingAnimation];
    [[HttpNewBaseService sharedClient] getRequestOperation:@"goods_comment/comment_delete" paramDictionary:dic onCompletion:^(NSString *responseString) {
        [self.view stopLoadingAnimation];
        NSDictionary * dic =[responseString JSONValue];
        if ([[dic objectForKey:@"status"] intValue] == 1) {
            
            [self.out_data_list removeObjectAtIndex:self.select_index];
            
            //删除成功了
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"删除成功!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        } else {
            [self showAlertView:@"温馨提示" subtitle:[dic objectForKey:@"message"]];
            sender.enabled=YES;
        }
    } onError:^(NSError *error) {
        [self.view stopLoadingAnimation];
        sender.enabled=YES;
        [self showAlertView:@"温馨提示" subtitle:@"网络断了！"];
    } onAnimated:YES];
}

- (void)doActionShowLargImg:(UIButton*)btn
{
    
}

- (void)doActionBBQ:(UIButton*)btn
{
    BuyProductViewController * buy = [[BuyProductViewController alloc] init];
    NSString * buy_url = [data_list objectForKey:@"buy_url"];
    if (buy_url == nil) {
        buy_url = @"http://www.taobao.com";
    }
    buy.stringurl =buy_url;
    
    buy.stringid = [data_list objectForKey:@"id"];
    buy.m_b_is_have_say=YES;
    
    buy.m_b_is_come_s=NO;
    NSDictionary * dic_groupon_status = [data_list objectForKey:@"groupon_status"];
    if (dic_groupon_status &&
        [dic_groupon_status isKindOfClass:[NSDictionary class]]) {
        
        buy.m_b_is_come_s=[[dic_groupon_status objectForKey:@"is_groupon"] boolValue];
        //buy.m_b_is_have_say = [[dic_groupon_status objectForKey:@"is_commented"] boolValue];
        
        buy.str_group_id=[dic_groupon_status objectForKey:@"id_groupon"];
        buy.end_time = [[dic_groupon_status objectForKey:@"end_time"] doubleValue];
        if ([dic_groupon_status objectForKey:@"price"] && [[dic_groupon_status objectForKey:@"price"] isKindOfClass:[NSString class]]) {
            buy.str_money=[dic_groupon_status objectForKey:@"price"];
        }
    }
    
    //share
    buy.str_share_name = [data_list objectForKey:@"name"];
    if (image_goods) {
        buy.image_share_ = image_goods.imageView.image;
    }
    
    [self.navigationController pushViewController:buy animated:YES];
}

- (void)haveSan:(UIButton*)sender
{
    sender.enabled=NO;
    
    NSString * str_bb_id = @"0";
    if (data_array_list && [data_array_list isKindOfClass:[NSArray class]]) {
        if ([data_array_list count] > 0) {
            NSDictionary * dic_bb = [data_array_list objectAtIndex:0];
            if (dic_bb && [dic_bb isKindOfClass:[NSDictionary class]]) {
                str_bb_id = [dic_bb objectForKey:@"id"];
            }
        }
    }
    
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:str_bb_id, @"id", nil];
    
    [self.view startLoadingAnimation];
    
    [[HttpNewBaseService sharedClient] getRequestOperation:@"goods_comment/comment_useful_inc" paramDictionary:dic onCompletion:^(NSString *responseString) {
        [self.view stopLoadingAnimation];
        @try {
            NSDictionary * dic =[responseString JSONValue];
            if ([[dic objectForKey:@"status"] intValue] == 1) {
                //有用了
                [self showAlertView:@"温馨提示" subtitle:[dic objectForKey:@"message"]];
                if (data_list) {
                    //NSInteger a = [[data_list objectForKey:@"comment_sum"] integerValue]+1;
                    self.m_useful_sum=self.m_useful_sum+1;
                    NSString * str_bb = [NSString stringWithFormat:@"%d人觉得赞", self.m_useful_sum];
                    //[data_list setObject:str_bb forKey:@"comment_sum"];
                    self.label_people.text=str_bb;
                }
            } else {
                [self showAlertView:@"温馨提示" subtitle:@"不能重复评论!"];
            }
        } @catch (NSException *exception) {
            [self showAlertView:@"温馨提示" subtitle:@"服务器异常！"];
        } @finally {
        }
    } onError:^(NSError *error) {
        [self.view stopLoadingAnimation];
        [self showAlertView:@"温馨提示" subtitle:@"网络断了！"];
    } onAnimated:YES];
}

- (void)haveShare:(id)sender
{
    if (data_list) {
        /*
        //@"http://42.120.48.241/api.php/groupon/groupon_buy_comment/id/"
        //NSString * str_url = @"http://cherry8.com/api.php/groupon/groupon_buy_comment/id/";
        NSString * str_url = @"http://180.150.179.226/cherry/api.php/groupon/groupon_buy_comment/id/";
        
        NSString * str_id = [NSString stringWithFormat:@"%@%@", str_url, [data_list objectForKey:@"id"]];
        NSString * str_name = [data_list objectForKey:@"name"];
        
        NSString * str_send_info = [NSString stringWithFormat:@"%@  %@", str_name, str_id];
//        [UMSocialWechatHandler setWXAppId:@"wx42bae2a079770c21"
//                                appSecret:@"85762a1a96144f320249c0e3416074fe"
//                                      url:str_send_info];
        
        UIImage * image_bb = image_goods.imageView.image;
        
        [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeApp;

        [UMSocialData defaultData].extConfig.title = str_name;
        [UMSocialData defaultData].extConfig.wechatSessionData.url = str_id;
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = str_id;
        
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:@"53fc9df6fd98c5c9a0009069"
                                          shareText:str_send_info
                                         shareImage:image_bb
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToWechatSession, UMShareToWechatTimeline, nil]
                                           delegate:self];
        */
        NSString * str_name = [data_list objectForKey:@"name"];
        UIImage * image_bb = image_goods.imageView.image;
        
        //NSString * str_url_share_tuan = [NSString stringWithFormat:@"http://180.150.179.226/cherry/api.php/groupon/groupon_buy_comment/id/%@", [data_list objectForKey:@"id"]];
        NSString * str_url_share_tuan = [NSString stringWithFormat:@"http://cherry8.com/api.php/groupon/groupon_buy_comment/id/%@", [data_list objectForKey:@"id"]];
        
        NSString * str_send_info = [NSString stringWithFormat:@"樱桃优品--%@  %@ ", str_name, str_url_share_tuan];
        //@"http://www.weibo.com/2029912903/B3ogzA3p6"
        
        NSString * str_send_share_weixin = [NSString stringWithFormat:@"樱桃优品--%@", str_name];
        //樱桃优品  用心为您选择
        //    [UMSocialWechatHandler setWXAppId:@"wx42bae2a079770c21"
        //                            appSecret:@"85762a1a96144f320249c0e3416074fe"
        //                                  url:str_send_info];
        
        [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeApp;
        
        [UMSocialData defaultData].extConfig.title = str_send_share_weixin;//self.label_title.text;
        //[UMSocialData defaultData].extConfig.wechatSessionData.url = self.str_share_url_address;
        [UMSocialData defaultData].extConfig.wxMessageType=UMSocialWXMessageTypeWeb;
        [UMSocialData defaultData].extConfig.wechatSessionData.url=str_url_share_tuan;
        [UMSocialData defaultData].extConfig.wechatSessionData.shareText=[NSString stringWithFormat:@"樱桃优品 用心为您选择 %@",self.m_str_content];
        
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = str_url_share_tuan;//@"http://www.taobao.com";
        
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:@"53fc9df6fd98c5c9a0009069"
                                          shareText:str_send_info
                                         shareImage:image_bb
                                    shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToWechatSession, UMShareToWechatTimeline, nil]
                                           delegate:self];
    }
}

//实现回调方法（可选）：
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}


@end









































